﻿using System;
using System.Configuration;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace PAT.Util
{
    public class Reports
    {
        #region Atributos
        private String connectionString;
        #endregion

        #region Constructor
        /// <summary>
        /// 
        /// </summary>
        public Reports()
        {
            connectionString = ConfigurationManager.ConnectionStrings["PAT.Data.ConnectionString"].ConnectionString;
        }
        #endregion

        #region Metodos

        public DataSet GetReporteCitas(Byte IdEstadoCita, DateTime FechaInicio, DateTime FechaFin, Int32 IdTaller)
        {
            DataSet dsReport = new DataSet();
            using (SqlConnection connection = new SqlConnection(this.connectionString))
            {
                try
                {
                    connection.Open();
                    SqlCommand comm = new SqlCommand("CUST_Reporte_Citas", connection);
                    comm.CommandType = CommandType.StoredProcedure;
                    
                    comm.Parameters.Add(new SqlParameter("@ID_ESTADO_CITA", IdEstadoCita));
                    comm.Parameters.Add(new SqlParameter("@FECHA_INICIAL", FechaInicio));
                    comm.Parameters.Add(new SqlParameter("@FECHA_FINAL", FechaFin));
                    if(IdTaller != -1)
                        comm.Parameters.Add(new SqlParameter("@ID_TALLER", IdTaller));
                    else
                        comm.Parameters.Add(new SqlParameter("@ID_TALLER", DBNull.Value));

                    SqlDataAdapter adpt = new SqlDataAdapter(comm);
                    adpt.Fill(dsReport);
                }
                catch { }
                finally
                {
                    connection.Close();
                }
            }
            return dsReport;
        }

        public DataSet GetReporteOrdenes(Byte IdCargoOrden, DateTime FechaInicio, DateTime FechaFin, Int32 IdTaller)
        {
            DataSet dsReport = new DataSet();
            using (SqlConnection connection = new SqlConnection(this.connectionString))
            {
                try
                {
                    connection.Open();
                    SqlCommand comm = new SqlCommand("CUST_Reporte_Ordenes", connection);
                    comm.CommandType = CommandType.StoredProcedure;

                    if (IdCargoOrden != 0)
                        comm.Parameters.Add(new SqlParameter("@ID_CARGO_ORDEN", IdCargoOrden));
                    else
                        comm.Parameters.Add(new SqlParameter("@ID_CARGO_ORDEN", DBNull.Value));

                    comm.Parameters.Add(new SqlParameter("@FECHA_INICIAL", FechaInicio));
                    comm.Parameters.Add(new SqlParameter("@FECHA_FINAL", FechaFin));
                    if (IdTaller != -1)
                        comm.Parameters.Add(new SqlParameter("@ID_TALLER", IdTaller));
                    else
                        comm.Parameters.Add(new SqlParameter("@ID_TALLER", DBNull.Value));

                    SqlDataAdapter adpt = new SqlDataAdapter(comm);
                    adpt.Fill(dsReport);
                }
                catch { }
                finally
                {
                    connection.Close();
                }
            }
            return dsReport;
        }

        #endregion
    }
}
